<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/9 0009
 * Time: 11:01
 */

namespace app\wap\controller;
use think\Db;

class News extends Base
{
        public function index(){
            $data = Db::name('news')->where('is_del= 0 and is_show =1 and sign="mobile" ')->order('sort desc,id desc')->limit(10)->select();
            $this->assign('data',$data);
            //判断是否有第二页的数据
            $type =1;
            $next_data= Db::name('news')->where('is_del=0 and is_show=1 and sign="mobile"')->page(2,10)->select();
            if(!$next_data){
                $type =2;
            }
            $this->assign('type',$type);
            $this->assign('data_seo',getColumnseo(7));
            return $this->fetCh();
    }

        public function nr(){
            $id = intval(input('param.id'));
            if($id){
                $data = Db::name('news')->where('id',$id)->find();

                $this->assign('data',$data);
            }
            return $this->fetch();
        }


        public function getMore(){
            $page = intval(input('page'));
            $type =1;
            $res= Db::name('news')->where('is_del=0 and is_show=1 and sign="mobile"')->page($page,10)->select();
            $next_data= Db::name('news')->where('is_del=0 and is_show=1 and sign="mobile"')->page($page+1,10)->select();
            if(!$next_data){
                $type =2;
            }
            if($res){
                return json(['code'=>1,'data'=>$res,'type'=>$type]);
            }else{
                return json(['code'=>0,'msg'=>'没有更多了']);
            }

        }


}